<template>
  <header class="common-header">
    <div class="header-content">
      <div class="logo">
        <img src="@/assets/logo.png" alt="健康预测平台" class="logo-img" />
        <h1>健康预测平台</h1>
      </div>
      <nav class="nav">
        <router-link v-if="userStore.isUser" to="/user/dashboard">首页</router-link>
        <router-link v-if="userStore.isUser" to="/user/health-data">健康数据</router-link>
        <router-link v-if="userStore.isUser" to="/user/data-history">数据历史</router-link>
        <router-link v-if="userStore.isUser" to="/user/predictions">预测结果</router-link>
        <router-link v-if="userStore.isUser" to="/user/system-feedback">系统反馈</router-link>
        
        <!-- 调整统计员端导航顺序 -->
        <router-link v-if="userStore.isStatistician" to="/statistician/health-data-dashboard">健康数据可视化大屏</router-link>
        <router-link v-if="userStore.isStatistician" to="/statistician/dashboard">统计面板</router-link>
        <router-link v-if="userStore.isStatistician" to="/statistician/data-export">系统反馈</router-link>
        
        <router-link v-if="userStore.isAdmin" to="/admin/dashboard">首页</router-link>
        <router-link v-if="userStore.isAdmin" to="/admin/user-management">用户管理</router-link>
        <router-link v-if="userStore.isAdmin" to="/admin/statistician-management">疾控中心统计员管理</router-link>
        <router-link v-if="userStore.isAdmin" to="/admin/system-config">系统配置</router-link>
      </nav>
      <div class="user-info">
        <!-- 只在用户端和统计员端显示公告 -->
        <Notice v-if="userStore.isUser || userStore.isStatistician" />
        <span>{{ userStore.username }}</span>
        <router-link v-if="userStore.isLoggedIn" :to="`/${userStore.role}/profile`">个人中心</router-link>
        <button v-if="userStore.isLoggedIn" @click="handleLogout" class="logout-btn">退出登录</button>
      </div>
    </div>
  </header>
</template>

<script>
import { useUserStore } from '@/stores/user'
import { useRouter } from 'vue-router'
import Notice from './Notice.vue'

export default {
  name: 'Header',
  components: {
    Notice
  },
  setup() {
    const userStore = useUserStore()
    const router = useRouter()
    
    const handleLogout = () => {
      userStore.logout()
      router.push('/login')
    }
    
    return {
      userStore,
      handleLogout
    }
  }
}
</script>

<style scoped>
.common-header {
  background-color: #0072c6;
  color: #fff;
  padding: 0 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 60px;
  max-width: 1400px;
  margin: 0 auto;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-img {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.logo h1 {
  font-size: 20px;
  margin: 0;
}

.nav {
  display: flex;
  gap: 20px;
}

.nav a {
  color: #fff;
  text-decoration: none;
  padding: 5px 10px;
  border-radius: 4px;
}

.nav a:hover {
  background-color: rgba(255, 255, 255, 0.2);
  text-decoration: underline;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 15px;
  position: relative;
}

.logout-btn {
  background-color: #e74c3c;
  color: #fff;
  border: none;
  padding: 5px 15px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: background-color 0.3s;
}

.logout-btn:hover {
  background-color: #c0392b;
}
</style>